def xor_sum(edges, n, m):
    # 初始化邻接表，用于表示图
    graph = {i: set() for i in range(1, n + 1)}
    for u, v, w in edges:
        graph[u].add((v, w))
        graph[v].add((u, w))  # 如果是无向图，需要添加这行

    # 初始化方案数为0
    count = 0

    # 非递归深度优先搜索
    def dfs(node, current_xor, remaining_money, stack):
        if remaining_money == 0:
            # 如果剩余的钱为0，说明找到了一个有效的方案
            nonlocal count
            count += 1
            return

        stack.append((node, current_xor, remaining_money))
        for neighbor, weight in graph[node]:
            # 计算新的异或和和剩余的钱
            new_xor = current_xor ^ weight
            new_remaining_money = m - new_xor
            if new_remaining_money >= 0:
                dfs(neighbor, new_xor, new_remaining_money, stack)

        # 回溯
        stack.pop()

    # 从每个节点开始遍历所有可能的路径
    for i in range(1, n + 1):
        stack = []
        dfs(i, 0, m, stack)

    return count

# 输入
n, m = map(int, input().split())
edges = [tuple(map(int, input().split())) for _ in range(n - 1)]

# 输出方案数
print(xor_sum(edges, n, m))